package cl.jsoftlabs.gwt.soccer.client.ui.home;


import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.TabItem;
import com.extjs.gxt.ui.client.widget.TabPanel;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.VerticalPanel;


public class HomePage extends ContentPanel{
    
    private TabPanel tabPanel = new TabPanel();
    
    BorderLayoutData menuBarToolBarLayoutData = new BorderLayoutData(LayoutRegion.NORTH, 55);
    BorderLayoutData leftSidebarLayoutData = new BorderLayoutData(LayoutRegion.WEST, 150);
    BorderLayoutData mainContentsLayoutData = new BorderLayoutData(LayoutRegion.CENTER);
    BorderLayoutData rightSidebarLayoutData = new BorderLayoutData(LayoutRegion.EAST, 150);
    BorderLayoutData footerLayoutData = new BorderLayoutData(LayoutRegion.SOUTH, 20);

    public HomePage()
    {

        setSize(1000,800);
        setHeaderVisible(false);
  
        BorderLayout layout = new BorderLayout();
        setLayout(layout);
        
        //Layout para menu y barra de herramientas superior
        
        menuBarToolBarLayoutData.setMargins(new Margins(5));

        //Layout panel izquierdo
        
        leftSidebarLayoutData.setSplit(true);
        leftSidebarLayoutData.setCollapsible(true);
        leftSidebarLayoutData.setMargins(new Margins(0, 5, 0, 5));

        //Layout para contenido principal
        
        mainContentsLayoutData.setMargins(new Margins(0));

        //Layout para panel derecho
        rightSidebarLayoutData.setSplit(true);
        rightSidebarLayoutData.setCollapsible(true);
        rightSidebarLayoutData.setMargins(new Margins(0, 5, 0, 5));

        //Layout para el panel inferior footer
        footerLayoutData.setMargins(new Margins(5));

        //PANEL SUPERIOR, MENU Y BARRA DE HERRAMIENTAS
        add(new PanelSuperior(), menuBarToolBarLayoutData);
        
        
        tabPanel.setMinTabWidth(115);
        //tabPanel.setResizeTabs(true);
        //tabPanel.setAnimScroll(true);
        tabPanel.setTabScroll(true);
        tabPanel.setCloseContextMenu(true);

        add(tabPanel, mainContentsLayoutData);
        add(getRightSidebar(), rightSidebarLayoutData);
        add(getFooter(), footerLayoutData);
       
    }

    public void addTab(String text, LayoutContainer layoutContainer){
    	//GWT.log(tabPanel.getItemByItemId("busqueda: "+layoutContainer.getItemId()).toString());
        TabItem item = new TabItem();
        item.setText(text);
        item.setLayout(new FitLayout());
        item.setClosable(true);
        item.add(layoutContainer);
        
        tabPanel.add(item);
        tabPanel.setSelection(item);
    }

    private PanelIzquierdo acordeonNavegacion;
    
    @SuppressWarnings("unused")
	private void getPanelIzquierdo(){
    	this.acordeonNavegacion = new PanelIzquierdo();
    	add(acordeonNavegacion, leftSidebarLayoutData);
    }


    private ContentPanel getRightSidebar(){
        ContentPanel rightSidebarPanel = new ContentPanel();
        rightSidebarPanel.setHeading("Right Sidebar");
        return rightSidebarPanel;
    }

    private HorizontalPanel getFooter()
    {

        HorizontalPanel footerPanel = new HorizontalPanel();

        Label label = new Label("Probando GWT y JPA");
        HTML htmlChile = new HTML("<img src=\"img/banderas/cl.png\" />");
        footerPanel.add(label);
        footerPanel.add(htmlChile);
        footerPanel.setHorizontalAlign(HorizontalAlignment.RIGHT);
        return footerPanel;
    }

}
